package com.ruoyi.web.controller.system;

import java.util.List;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysFields;
import com.ruoyi.system.service.ISysFieldsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 档案字段设置Controller
 * 
 * @author ruoyi——hsl
 * @date 2022-02-15
 */
@RestController
@RequestMapping("/system/fields")
public class SysFieldsController extends BaseController
{
    @Autowired
    private ISysFieldsService sysFieldsService;

    /**
     * 查询档案字段设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:fields:list')")
    @ApiOperation("查询档案字段设置列表")
    @GetMapping("/list")
    public TableDataInfo list(SysFields sysFields)
    {
        startPage();
        List<SysFields> list = sysFieldsService.selectSysFieldsList(sysFields);
        return getDataTable(list);
    }

    /**
     * 导出档案字段设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:fields:export')")
    @Log(title = "档案字段设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysFields sysFields)
    {
        List<SysFields> list = sysFieldsService.selectSysFieldsList(sysFields);
        ExcelUtil<SysFields> util = new ExcelUtil<SysFields>(SysFields.class);
        return util.exportExcel(list, "fields");
    }

    /**
     * 根据表编号获取档案字段设置
     */
    @PreAuthorize("@ss.hasPermi('system:fields:query')")
    @ApiOperation("根据表编号获取档案字段设置")
    @ApiImplicitParam(name = "recNo", value = "表编号", required = true, dataType = "String", paramType = "传表编号")
    @GetMapping("/get")
    public TableDataInfo getInfo(SysFields sysFields)
    {
        startPage();
        sysFields.setTableNo(sysFields.getRecNo());
        List<SysFields> sysField = sysFieldsService.selectSysFieldsByTableId(sysFields);
        return getDataTable(sysField);
    }

    /**
     * 获取档案字段设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fields:query')")
    @ApiOperation("获取档案字段设置详细信息")
    @ApiImplicitParam(name = "recNo", value = "字段编号", required = true, dataType = "String", paramType = "传字段编号")
    @GetMapping(value = "/select/{recNo}")
    public AjaxResult selectInfo(@PathVariable("recNo") String recNo)
    {
        return AjaxResult.success(sysFieldsService.selectSysFieldsById(recNo));
    }

    /**
     * 新增档案字段设置
     */
    @PreAuthorize("@ss.hasPermi('system:fields:add')")
    @Log(title = "档案字段设置", businessType = BusinessType.INSERT)
    @ApiOperation("新增档案字段设置")
    @ApiImplicitParam(name = "sysFields", value = "字段对象", required = true, dataType = "SysFields", paramType = "传字段对象")
    @PostMapping
    public AjaxResult add(@RequestBody SysFields sysFields)
    {
        return sysFieldsService.insertSysFields(sysFields);
    }

    /**
     * 修改档案字段设置
     */
    @PreAuthorize("@ss.hasPermi('system:fields:edit')")
    @Log(title = "档案字段设置", businessType = BusinessType.UPDATE)
    @ApiOperation("修改档案字段设置")
    @ApiImplicitParam(name = "sysFields", value = "字段对象", required = true, dataType = "SysFields", paramType = "传字段对象")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SysFields sysFields)
    {
        return sysFieldsService.updateSysFields(sysFields);
    }

    /**
     * 删除档案字段设置
     */
    @PreAuthorize("@ss.hasPermi('system:fields:remove')")
    @Log(title = "档案字段设置", businessType = BusinessType.DELETE)
    @ApiOperation("删除档案字段设置")
    @ApiImplicitParam(name = "recNos", value = "字段编号数组", required = true, dataType = "String[]", paramType = "传字段编号数组")
    @GetMapping("/{recNos}")
    public AjaxResult remove(@PathVariable String[] recNos)
    {
        return sysFieldsService.deleteSysFieldsByIds(recNos);
    }
}
